<template>
  <el-card>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column
        :width="item.width"
        :prop="item.prop"
        :label="item.label"
        v-for="item in options"
        :key="item.rid"
      >
        <template v-slot="{ row }" v-if="item.prop === 'state'">
          <el-tag
            type="success"
            class="mx-1"
            effect="dark"
            round
            v-if="row.state === '1'"
          >
            已完成
          </el-tag>
          <el-tag
            type="warning"
            class="mx-1"
            effect="dark"
            round
            v-if="row.state === '2'"
          >
            待完成
          </el-tag>
          <el-tag
            type="danger"
            class="mx-1"
            effect="dark"
            round
            v-if="row.state === '0'"
          >
            已取消
          </el-tag>
        </template>
        <template #default="{ row }" v-else-if="item.prop === 'action'">
          <template v-if="row.state === '2'">
            <el-button
              type="primary"
              size="small"
              @click="handleDialogValue(row)"
              >完成</el-button
            >
          </template>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script setup>
import { ref } from 'vue'
import { options } from './options'
import { getRecodeTest, editRecode1 } from '@/api/doctorRecode'
const total = ref(0)
const tableData = ref([])
const DoctorInfo = JSON.parse(localStorage.getItem('Doctoraccount'))
const initGetUsers = async () => {
  const res = await getRecodeTest(DoctorInfo)
  tableData.value = res.data.datas
  total.value = res.data.total
}
initGetUsers()

const handleDialogValue = async (row) => {
  await editRecode1({
    account: DoctorInfo,
    name: row.pname,
    ordertime: row.ordertime
  })
  initGetUsers()
}
</script>

<style lang="scss" scoped>
.header {
  padding-bottom: 16px;
  box-sizing: border-box;
}
</style>